/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Principal;

import com.atmel.atusbhidjni.AtUsbHidJni;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author linton
 */
public class comandosUSB extends AtUsbHidJni{

    



    public comandosUSB() {
        loadLibraryUsbHid();
    }

    public boolean conectar(int pid, int vid) {

        if (findHidDevice(pid, vid) == 1) {
            return true;
        } else {
            return false;
        }
    }

    public boolean enviar(byte[] bufferSaida) {
        try {
            Thread.sleep(0);
        } catch (InterruptedException ex) {
            Logger.getLogger(comandosUSB.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (writeData(bufferSaida)) {
            return true;
        } else {
            return false;
        }
    }

    public byte[] receber() {
        try {
            Thread.sleep(0);
        } catch (InterruptedException ex) {
            Logger.getLogger(comandosUSB.class.getName()).log(Level.SEVERE, null, ex);
        }
        return readData();

    }

    public void finalizarComunicacao() {
        UnloadloadLibraryUsbHid();
    }  
}